/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#pragma once
#include <map>

/**
==============================
An ICommand is an interface for
a function to be executed by the console
==============================
*/
class ICommand 
{
public:
    virtual void Exec( std::string &s ) =0;
};

/** Short cuts */
typedef std::map< std::string, ICommand* > type_Commands;

/**
===============================
Cmds is a holder for all the functions allowed
===============================
*/
class Cmds 
{
public:
    Cmds(void) { cmdlist_f.Set( this ); AddCommand( &cmdlist_f, "cmdlist" ); };

    /** Get a Console command */
    ICommand* GetCommand( const std::string &s) { 
		if( HasCommand( s ) )
			return cmdList[s];
		return NULL;
	};
    /** Add a command */
    void AddCommand( ICommand* cmd,  const std::string &s) { cmdList[s] = cmd; };

    /** Remove a command */
    void RemoveCommand( const std::string &s ) { 
        if ( HasCommand( s ) )
            cmdList.erase( cmdList.find(s) );     
    };

    /** Test to see if the command is present */
    bool HasCommand( const std::string &s ) {
        return ( cmdList.find(s) != cmdList.end() );
    };

    /** Get all commands */
    type_Commands& GetAllCommands() { return cmdList; };

private:
    type_Commands cmdList;

    /** Cmd list command */
    class CmdList_f : public ICommand
    {
    public:
        CmdList_f() {};
        void Set(Cmds *cmd) { m_cmd = cmd; };
        void Exec(std::string &s);
        ~CmdList_f() {};
        // retrieve all the command names
        Cmds *m_cmd;
    }; CmdList_f  cmdlist_f;

public:
    virtual ~Cmds(void) {
        RemoveCommand( "cmdlist" );
    };
};


